﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace 毕业设计__排课软件
{
    /// <summary>
    /// SJ.xaml 的交互逻辑
    /// </summary>
    public partial class SJ : Window
    {
        List<SJlesson> Sj = new List<SJlesson>();
        string _dbPath;
        public SJ()
        {
            InitializeComponent();
            //Sj.Add(new SJlesson { lesson_num = "1，2节", js = "1308", lesson = "软件工程", teacher = "夏大伟", week = "1-17周", Class = "软件一班" });
            //Sj.Add(new SJlesson { lesson_num = "1，2节", js = "1308", lesson = "软件工程", teacher = "夏大伟", week = "1-17周", Class = "软件一班" });
            //Sj.Add(new SJlesson { lesson_num = "1，2节", js = "1308", lesson = "软件工程", teacher = "夏大伟", week = "1-17周", Class = "软件一班" });
            //Sj.Add(new SJlesson { lesson_num = "1，2节", js = "1308", lesson = "软件工程", teacher = "夏大伟", week = "1-17周", Class = "软件一班" });
            //Sj.Add(new SJlesson { lesson_num = "1，2节", js = "1308", lesson = "软件工程", teacher = "夏大伟", week = "1-17周", Class = "软件一班" });
            //dg1.ItemsSource = Sj;
        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (WindowState == WindowState.Maximized)
            {
                gd1.Width = ActualWidth - 10;
                gd1.Height = ActualHeight - 10;
                gd2.Width = ActualWidth - 10;
                gd2.Height = ActualHeight - 10;
                gd3.Width = ActualWidth - 10;
                gd3.Height = ActualHeight - 10;
                gd4.Width = ActualWidth - 10;
                gd4.Height = ActualHeight - 10;
                gd5.Width = ActualWidth - 10;
                gd5.Height = ActualHeight - 10;
                gd6.Width = ActualWidth - 10;
                gd6.Height = ActualHeight - 10;
            }
            if (WindowState == WindowState.Normal)
            {
                gd1.Width = ActualWidth - 10;
                gd1.Height = ActualHeight - 10;
                gd2.Width = ActualWidth - 10;
                gd2.Height = ActualHeight - 10;
                gd3.Width = ActualWidth - 10;
                gd3.Height = ActualHeight - 10;
                gd4.Width = ActualWidth - 10;
                gd4.Height = ActualHeight - 10;
                gd5.Width = ActualWidth - 10;
                gd5.Height = ActualHeight - 10;
                gd6.Width = ActualWidth - 10;
                gd6.Height = ActualHeight - 10;
            }
        }

        private void tb1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var path0 = Environment.CurrentDirectory;
            var path1 = path0.Substring(0, path0.LastIndexOf("\\", StringComparison.Ordinal));
            var path2 = path1.Substring(0, path1.LastIndexOf("\\", StringComparison.Ordinal));
            _dbPath = path2 + "\\DB\\bs_pk.db";
            Sj.Clear();
            if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周一 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__1_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg1.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周二 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__2_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg2.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周三 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__3_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg3.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周四 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__4_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg4.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周五 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__5_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg5.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:所有 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.day_num = (Convert.ToInt32(tr["Teaching_Time"]) % 100 / 10).ToString();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg6.ItemsSource = Sj;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var path0 = Environment.CurrentDirectory;
            var path1 = path0.Substring(0, path0.LastIndexOf("\\", StringComparison.Ordinal));
            var path2 = path1.Substring(0, path1.LastIndexOf("\\", StringComparison.Ordinal));
            _dbPath = path2 + "\\DB\\bs_pk.db";
            Sj.Clear();
            if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周一 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__1_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg1.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周二 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__2_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg2.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周三 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__3_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg3.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周四 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__4_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg4.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:周五 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID and Teaching_Time like '__5_' order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg5.ItemsSource = Sj;
            }
            else if (tb1.SelectedItem.ToString() == "System.Windows.Controls.TabItem Header:所有 Content:")
            {
                using (var conn1 = new SQLiteConnection())
                {
                    var connsb = new SQLiteConnectionStringBuilder { DataSource = _dbPath };
                    conn1.ConnectionString = connsb.ToString();
                    conn1.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn1))
                    {
                        string sql1 = string.Format("select Teaching_Time,Classroom_Name,Course_Name,Teacher_Name,Grade,major,Class from Configuration_Info, Lesson_Info, Classroom_Info, Teacher_Info, Class_Info where Configuration_Info.Course_ID = Lesson_Info.Course_ID and Configuration_Info.Teacher_ID = Teacher_Info.Teacher_ID and Configuration_Info.Classroom_ID = Classroom_Info.Classroom_ID and Configuration_Info.Class_ID = Class_Info.Class_ID order BY Teaching_Time ASC,Course_Name ASC");
                        cmd.CommandText = sql1;
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        DataSet data = new DataSet();
                        adapter.Fill(data);
                        DataTable table = data.Tables[0];
                        foreach (DataRow tr in table.Rows)
                        {
                            SJlesson temp = new SJlesson();
                            temp.day_num = (Convert.ToInt32(tr["Teaching_Time"]) % 100 / 10).ToString();
                            temp.lesson_num = (Convert.ToInt32(tr["Teaching_Time"]) % 10).ToString();
                            temp.js = tr["Classroom_Name"].ToString();
                            temp.lesson = tr["Course_Name"].ToString();
                            temp.teacher = tr["Teacher_Name"].ToString();
                            temp.week = (Convert.ToInt32(tr["Teaching_Time"]) / 100).ToString();
                            temp.Class = tr["Grade"].ToString() + tr["major"].ToString() + tr["Class"].ToString();
                            Sj.Add(temp);
                        }
                    }
                }
                dg1.ItemsSource = null;
                dg2.ItemsSource = null;
                dg3.ItemsSource = null;
                dg4.ItemsSource = null;
                dg5.ItemsSource = null;
                dg6.ItemsSource = null;
                dg6.ItemsSource = Sj;
            }
        }
    }
}
